//
// Created by liugd on 24-7-19.
//

#include "../headers/common.h"

char readMenuSelection(int options) {

    string str;
    while (true) {
        getline(cin, str);
        if (str.size() != 1 || str[0]-'0' <= 0 || str[0]-'0' > options) {
            cout << "输入错误，请重新输入:";
//            break;
        } else {
            break;
        }
    }
    return str[0];
}

bool readQuitConfirm() {
    bool resutl = true;
    string str;
    while (true) {
        getline(cin, str);
        if ('Y' == str[0] ) {
            break;
        } else {
            cout << "...加载主菜单";
            resutl= false;
            break;
        }
    }
    return resutl;
}

double readAmount() {
    double amount;
    string str;
    while (true) {
        getline(cin, str);
        try {
            amount = stod(str);
            break;
        } catch (invalid_argument e) {
            cout << "请输入正确的数字";
        }

    }
    return amount;
}